package com.slipper.system.codeless.controller;

import com.slipper.util.Tool;
import jakarta.annotation.Resource;

import com.slipper.constants.Constants;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.slipper.system.codeless.bo.DataTableBO;
import com.slipper.system.codeless.service.DataTableService;
import com.slipper.util.ResultUtil;

/**
 * 数据表格信息表
 */
@RestController
@RequestMapping("/system/dataTable")
public class DataTableController {
    @Resource
    private DataTableService dataTableService;
    
    @PostMapping(value = "/queryBy")
    public String queryBy(@RequestBody DataTableBO bo) {
        if(Tool.isBlank(bo.getId())) {
            return ResultUtil.failureResult("数据获取失败！");
        }
        return ResultUtil.successResult(dataTableService.queryBy(bo.getId()));
    }

    @PostMapping(value = "/queryList")
    public String queryList(@RequestBody DataTableBO bo) {
        return ResultUtil.successResult(dataTableService.queryList(bo));
    }
    
    @PostMapping(value = "/queryPage")
    public String queryPage(@RequestBody DataTableBO bo) {
        return ResultUtil.successResult(dataTableService.queryPage(bo));
    }

    @PostMapping(value = "/save")
    public String save(@RequestBody DataTableBO bo) {
        bo.setOperateId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.saveResult(dataTableService.save(bo));
    }

    @PostMapping(value = "/copy")
    public String copy(@RequestBody DataTableBO bo) {
        bo.setOperateId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.operateResult(dataTableService.copy(bo), "复制");
    }

    @PostMapping(value = "/delete")
    public String delete(@RequestBody DataTableBO bo) {
        return ResultUtil.deleteResult(dataTableService.delete(bo));
    }
}
